package com.scuec.groupfive.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scuec.groupfive.entity.Post;
import com.scuec.groupfive.mapper.CommunityMapper;
import com.scuec.groupfive.service.CommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommunityServiceImpl implements CommunityService {

    @Autowired
    private CommunityMapper communityMapper;

    @Override
    public PageInfo<Post> getAllPostsWithUserInfo(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Post> posts = communityMapper.getAllPostsWithUserInfo();
        return new PageInfo<>(posts);
    }

    @Override
    public PageInfo<Post> getPostsByUsername(String username, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Post> posts = communityMapper.getPostsByUsername(username);
        return new PageInfo<>(posts);
    }

    @Override
    public PageInfo<Post> getPostsByTitle(String title, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Post> posts = communityMapper.getPostsByTitle(title);
        return new PageInfo<>(posts);
    }
}